package com.quzi.kettle.activitise.main;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.quzi.kettle.R;
import com.quzi.kettle.activitise.BaseActivity;
import com.quzi.kettle.activitise.process.DeviceList;
import com.quzi.kettle.view.StatusViewGroup;
import com.quzi.kettle.view.TitleBarHandler;
import com.quzi.kettle.view.TitleBarView;

public class MainActivity extends BaseActivity{

	TitleBarView titleView;
	SlidingMenu menu;
	StatusViewGroup statusView;
	
	private LinearLayout menu_all_device, menu_share, menu_upgread;
	
	private int progress = 0;
	
	private Handler UIHandler = new Handler(){
	@Override
		public void dispatchMessage(Message msg) {
			// TODO Auto-generated method stub
			super.dispatchMessage(msg);
			switch(msg.what){
			case 0:
				statusView.updateView(progress);
				progress ++;
				if(progress >= 100){
					progress = 0;
				}
				UIHandler.sendEmptyMessageDelayed(0, 100);
				break;
			}
		}	
	};
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.layout_main);
		initTitleBar();	
		
		statusView = (StatusViewGroup) findViewById(R.id.viewgroup);
		initMenu();
		UIHandler.sendEmptyMessage(0);
	}
	
	private void initMenu(){
		menu = new SlidingMenu(getApplicationContext());
		menu.setMode(SlidingMenu.LEFT);
		menu.setTouchModeAbove(SlidingMenu.LEFT);
		menu.setFadeDegree(0.35f);

		LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());
		View slidemenuleftview = layoutInflater.inflate(R.layout.slidingmenuview,
				null);
		
		menu_upgread = (LinearLayout) slidemenuleftview.findViewById(R.id.menu_upgrade);
		
		menu_all_device.setOnClickListener(this);
		menu_share.setOnClickListener(this);
		menu_upgread.setOnClickListener(this);
		
		menu.setMenu(slidemenuleftview);
		menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
	}
	
	@Override
	protected void initTitleBar() {
		// TODO Auto-generated method stub
		super.initTitleBar();
		titleView = (TitleBarView) findViewById(R.id.titleview);
		titleView.setTitle("我的水壶");
		titleView.setTitleBarClickListener(new TitleBarHandler() {
			
			@Override
			public void ClickRight() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void ClickLeft() {
				// TODO Auto-generated method stub
				menu.toggle();
			}
		});
	}
	
	
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch(view.getId()){
		}
	}

}
